<?php if (!defined('THINK_PATH')) exit(); /*a:1:{s:65:"/var/www/fish/application/crm/view/callplatform/editCustomer.html";i:1519609088;}*/ ?>
<!DOCTYPE html>
<html>
    
    <head>
        <meta charset="UTF-8">
        <title>小鱼ADMIN</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
        <link rel="stylesheet" href="/public/static/css/font.css">
        <link rel="stylesheet" href="/public/static/css/bgadmin.css">
		<link href="/public/static/lib/address/css/city-picker.css" rel="stylesheet" type="text/css" />
        <script type="text/javascript" src="/public/static/js/jquery-1.8.0.min.js"></script>
        <script src="/public/static/js/js/jquery-1.9.1.min.js"></script>
        <script type="text/javascript" src="/public/static/lib/layui/layui.js" charset="utf-8"></script>
        <script type="text/javascript" src="/public/static/js/bgadmin.js"></script>
        <script type="text/javascript" src="/public/static/js/jquery.form.js"></script>
		<script type="text/javascript" src="/public/static/js/pbx.js"></script>
		<script type="text/javascript">
			var CTI_IP = "192.168.88.59:8888"; 
			var exten = "<?php echo $_SESSION['user_info']['extension']; ?>";
		</script>
    </head>
    
    <body>
        <div class="bg-body">
            <form  action="#" method="post" id="basicCustomer" class="layui-form">
                <input type="hidden" name="customer_code" value="<?php echo $customerData['customer_code']; ?>">
                <input type="hidden" name="id" id="id" value="<?php echo $id; ?>">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">
                            客户编码：
                        </label>
                        <div class="layui-input-inline">
                            <input type="text" value="<?php echo $customerData['customer_code']; ?>" disabled class="layui-input layui-bg-gray">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">
                            <span class="bg-red">*&nbsp;&nbsp;</span>客户姓名：
                        </label>
                        <div class="layui-input-inline">
                            <input type="text" id="name" name="name" value="<?php echo $customerData['name']; ?>" lay-verify="required" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">
                            客户性别：
                        </label>
                        <div class="layui-input-inline">
                            <select name="sex" id="sex" autocomplete="off" class="layui-input">
                                <option value="">请选择</option>
                                <option value="1">男</option>
                                <option value="2">女</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">
                            客户年龄：
                        </label>
                        <div class="layui-input-inline">
                            <input type="text" id="age" name="age" value="<?php echo $customerData['age']; ?>" value="<?php echo $customerData['age']; ?>" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
                <?php if(empty($customerData['province'])): ?>
                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">
                        导入地址：
                    </label>
                    <div class="layui-input-block" id="address_select" style="">
                        <input class="layui-input layui-bg-gray" value="<?php echo $customerData['address']; ?>" disabled style="width:50%">
                    </div>
                </div>
                <?php endif; ?>
				<div class="layui-form-item">
					<label class="layui-form-label">
						<span class="bg-red">*&nbsp;&nbsp;</span>所在地区：
					</label>
					<div class="layui-input-block">
						<div style="position: relative;">
							<input id="city-picker3" style="width:50%;line-height:30px;" class="form-control" name="location_address" readonly lay-verify="required" type="text" value="<?php echo $customerData['province']; ?>/<?php echo $customerData['city']; ?>/<?php echo $customerData['district']; ?>" data-toggle="city-picker">
						</div>
					</div>
				</div>
				<div class="layui-form-item layui-form-text">
					<label class="layui-form-label">
						<span class="bg-red">*&nbsp;&nbsp;</span>详细地址：
					</label>
					<div class="layui-input-block" id="address_select" style="">
						<input class="layui-input"  placeholder="建议您如实填写详细收货地址，例如街道名称，门牌号码，楼层和房间号等信息" lay-verify="required"  name="address_details" value="<?php if($customerData['province']): ?><?php echo $customerData['address']; endif; ?>" lay-verify="required" style="width:50%">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label"></label>
					<a class="layui-btn" lay-submit="" id="saveCustomer" lay-filter="saveCustomer"><i class="iconfont1">&#xe6b2; </i>保存</a>
                    <a class="layui-btn layui-btn-warm" onclick="call_outbound('<?php echo $customerData['customer_code']; ?>');"><i class="iconfont1">&#xe6f1; </i>拨号1</a>
                    <a class="layui-btn layui-btn-warm" lay-submit="" id="" lay-filter=""><i class="iconfont1">&#xe6ec; </i>拨号2</a>
				</div>
            </form>
        </div>
        <div class="bg-body">
            <?php if(($username == 'admin') OR ($priv['order'] == 'Y')): ?>
            <form  action="#" method="post" id="mainForm" class="layui-form">
                <fieldset class="layui-elem-field layui-field-title">
                  <legend>病情信息</legend>
                </fieldset>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">
                            病情类别：
                        </label>
                        <div class="layui-input-inline">
                            <select name="illness_type" id="illness_type" class="layui-input">
                                <option value="">请选择</option>
                                <?php echo $illness_option; ?>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">
                        病情描述：
                    </label>
                    <div class="layui-input-inline">
                        <textarea class="layui-textarea" name="description" id="description" cols="60" rows="3" style="resize:none"></textarea>
                    </div>
                </div>
                <fieldset class="layui-elem-field layui-field-title">
                  <legend>订单信息</legend>
                </fieldset>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">
                            <span class="bg-red">*&nbsp;&nbsp;</span>收货人：
                        </label>
                        <div class="layui-input-inline">
                            <input type="text" readonly="readonly" id="consignee_id" name="consignee" required="" value="<?php echo $customerData['name']; ?>" lay-verify="required"
                            autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">
                            <span class="bg-red">*&nbsp;&nbsp;</span>下单时间：
                        </label>
                        <div class="layui-input-inline">
                            <input type="text" readonly="readonly" id="createtime_id" name="createtime" required="" lay-verify="required"
                            autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <?php if(($username == 'admin') OR ($priv['display_phone'] == 'Y')): ?>
                    <div class="layui-inline">
                        <label class="layui-form-label">
                            <span class="bg-red">*&nbsp;&nbsp;</span>收货手机：
                        </label>
                        <div class="layui-input-inline">
                            <input type="text" readonly="readonly" id="phone_id" name="phone" required="" value="<?php echo $customerData['phone1']; ?>" lay-verify="required"
                            autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">
                            收货电话：
                        </label>
                        <div class="layui-input-inline">
                            <input type="text" readonly="readonly" id="telephone_id" name="telephone" value="<?php echo $customerData['telephone']; ?>" lay-verify=""
                            autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <?php endif; ?>
                </div>  
                <div class="layui-form-item layui-form-text">
                    <div class="layui-inline">
                    <label for="desc" class="layui-form-label">
                        <span class="bg-red">*&nbsp;&nbsp;</span>收货地址：
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" name="delivery_address" id="delivery_address_id" required="" lay-verify="required" autocomplete="off" placeholder="请输入收货地址" value="<?php echo $customerData['province']; ?> <?php echo $customerData['city']; ?> <?php echo $customerData['district']; ?> <?php echo $customerData['address']; ?>" style="width:520px;" class="layui-input">
                    </div>
                    <a style="margin-top:5px;" onclick="synchroAddress('<?php echo $customerData['customer_code']; ?>','<?php echo $id; ?>');" class="layui-btn layui-btn-small"><i class="layui-icon">&#x1002;</i> 同步最新地址</a>
                    </div>
                </div>
                <input type="hidden" id="province_id" name="province" value="<?php echo $customerData['province']; ?>" />
                <input type="hidden" id="city_id" name="city" value="<?php echo $customerData['city']; ?>" />
                <input type="hidden" id="area_id" name="area" value="<?php echo $customerData['district']; ?>" />
                <input type="hidden" id="import_mark_id" name="import_mark" value="<?php echo $customerData['import_mark']; ?>" />
                <input type="hidden" id="task_id" name="task_id" value="<?php echo $id; ?>" />
                
                <div class="layui-form-item layui-form-text">
                    <div class="layui-inline">
                        <label for="desc" class="layui-form-label">
                            订单描述：
                        </label>
                        <div class="layui-input-inline">
                            <input type="text" name="description" id="description_id" autocomplete="off" placeholder="请输入" value="<?php echo $customerData['province']; ?>" style="width:520px;" class="layui-input">
                        </div>
                    </div>
                </div>

                <fieldset class="layui-elem-field layui-field-title">
                  <legend>商品信息</legend>
                </fieldset> 
                
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">
                            销售方案：
                        </label>
                        <div class="layui-input-inline">
                            <input type="text" id="good_name_id" onclick="bg_admin_show('选择方案','../Ordermanager/saleProgramList.html?task_id=<?php echo $id; ?>',600,400)" autocomplete="off" placeholder="点击选择销售方案" class="layui-input" readonly="readonly" >
                        </div>
                        <input type="hidden" value="" name="program_id" id="program_id"/>
                    </div>
                </div>
                
                <table class="layui-table" lay-data="{id: 'idTest'}" lay-filter="demo">
                  <thead>
                    <tr>
                        <th lay-data="{checkbox:true, LAY_CHECKED: true}"></th>
                        <th lay-data="{field:'id', align:'center', width:60 }">编号</th>
                        <th lay-data="{field:'good_name', align:'center', width:160 }">商品名称</th>
                        <th lay-data="{field:'good_num', width:100,sort: true}">商品货号</th>
                        <th lay-data="{field:'price', width:100,sort: true}">商品价格</th>
                        <th lay-data="{field:'cat_name', width:100 }">商品分类</th>
                        <th lay-data="{field:'goods_num', width:100 }">商品数量</th>
                        <th lay-data="{field:'goods_money', width:100 }">商品总价格</th>
                        <th lay-data="{field:'simple_description', width:200}">描述</th>
                        <!--<th lay-data="{fixed: 'right', width:100, align:'center', toolbar: '#barDemo'}">操作</th>-->
                    </tr>
                  </thead>
                </table>
                 
                <script type="text/html" id="barDemo">
                  <a class="layui-btn layui-btn-mini" lay-event="del">清除商品</a>
                </script>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">
                            订单总价：
                        </label>
                        <div class="layui-input-inline">
                            <input type="text" id="goods_amount_id" name="goods_amount" autocomplete="off"  class="layui-input" readonly="readonly" >
                        </div>
                    </div>
                    
                    <div class="layui-inline">
                        <label class="layui-form-label">是否改价格：</label>
                        <div class="layui-input-inline">
                            <select name="modify_price" id="modify_price_id" lay-filter="text_type" lay-verify="required">
                              <option value="N">否</option>
                              <option value="Y">是</option>
                            </select>
                        </div>
                    </div>
                    
                    <div class="layui-inline" id="modify_money_id" style="visibility:hidden;">
                        <label class="layui-form-label">
                            修改总价：
                        </label>
                        <div class="layui-input-inline">
                            <input type="text"   name="modify_money"
                            autocomplete="off" placeholder="请输入修改后的总价" class="layui-input">
                        </div>
                    </div>
                    
                </div>
                <div class="layui-form-item">
                    <a class="layui-btn" lay-submit=""  id="save" lay-filter="add">增加</a>
                </div>
            </form>
            <input type="hidden" id="customer_code_id" value="<?php echo $customerData['customer_code']; ?>"/>
            <?php endif; ?>
        </div>
    </body>
    <!-- <script type="text/javascript" src="/public/static/crm/js/servicecustomer/editCustomer.js"></script> -->
    <script src="/public/static/lib/address/js/city-picker.data.js"></script>
	<script src="/public/static/lib/address/js/city-picker.js"></script>
	<script src="/public/static/lib/address/js/main.js"></script>
    <script>
        var sex = '<?php echo $customerData['sex']; ?>';
        // alert(groups)
        layui.use('form', function(){
            var form = layui.form;
            $('#sex').val(sex);
            form.render();
        });

        layui.use('laydate', function(){
            var laydate = layui.laydate;
            laydate.render({
                elem: '#brithday'
            });

            laydate.render({
                elem: '#callbacktime',
                type: 'datetime'
            });
        });


        // var url = 
        function loadIframe (id, url) {
            if ($('#'+id).attr('src') == "") {
                $('#'+id).attr('src', url);
            }
        }

        var layer = layui.layer;
        var layedit = layui.layedit;
        var ajax_option_basic={  
            url:"updateCustomer",
            success:function(data){  
                var result = $.parseJSON(data); 
                if (result.success) {  
                    layer.alert(result.msg, {icon: 6}, function(index){
                        layer.close(index);
                    });
                } else {  
                    layer.alert(result.msg, {icon: 5}, function(index){
                        layer.close(index);
                    });
                }
            }
        };


        layui.use(['form', 'layedit'], function(){
            var form = layui.form
            ,layedit = layui.layedit;

            form.on('submit(saveCustomer)', function(data){
                $('#basicCustomer').ajaxSubmit(ajax_option_basic);
                return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
            });
        });



        /* addorder start */
        var layer = layui.layer;
        layui.use(['form','table'], function(){
            var form = layui.form;
            var table = layui.table;
            
            form.on('submit(add)', function(data){
                var checkStatus = table.checkStatus('idTest'); //test即为基础参数id对应的值
                var good_info = [];
                for(var key in checkStatus.data){ 
                    //good_info[key] = data[key].id+"-"+data[key].num+"-"+data[key].price+"-"+data[key].money;
                    //商品id-商品数量-商品单价-商品总价格-商品名称-商品货号-商品分类-商品品牌
                    good_info[key] = checkStatus.data[key].id+"-"+checkStatus.data[key].goods_num+"-"+checkStatus.data[key].price+"-"+checkStatus.data[key].goods_money+"-"+checkStatus.data[key].good_name+"-"+checkStatus.data[key].good_num+"-"+checkStatus.data[key].cat_name;
                }
                var info = good_info.join(",");
                if(!info){  //请填写商品信息
                    layer.msg('请设置订单商品信息', {
                        time: 2000, //2s后自动关闭
                    });
                    return false;
                }
                var customer_code = $("#customer_code_id").val();
                var ajax_option={  
                    url:"insertOrder?info="+info+"&customer_code="+customer_code,
                    success:function(data){  
                        var result = $.parseJSON(data); 
                        if (result.success) {  
                            layer.alert(result.msg, {icon: 6}, function(index){
                                layer.close(index);
                                parent.bg_admin_close();
                            });
                        } else {  
                            layer.alert(result.msg, {icon: 6}, function(index){
                                layer.close(index);
                            }); 
                        }  
                    }  
                };  
                
                $('#mainForm').ajaxSubmit(ajax_option);  
                return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
            }); 
            
            //监听工具条
            table.on('tool(demo)', function(obj){
              var data = obj.data;
              if(obj.event === 'del'){
                obj.del();
              }
            });
            
            form.on('select(text_type)', function(data){
                if(data.value=="Y"){
                    $("#modify_money_id").css('visibility','visible'); 
                }else{
                    $("#modify_money_id").css('visibility','hidden'); 
                }
            });
        });

        function addProduct(id,price,program_name){
            $.ajax({
                type : 'post',
                url : '/index.php/crm/SaleProgram/saleProgramGoods',
                data : 'id='+id,
                dataType : 'json',
                success : function (result) {
                    if(result){
                        layui.use('table', function(){
                            var table = layui.table;
                            table.init('demo', {
                                data: result.data,
                            });
                        })
                        $("#goods_amount_id").val(price);
                        $("#good_name_id").val(program_name);
                        $("#program_id").val(id);
                    }
                }
            })
        }

        $(function(){
            $("#createtime_id").val("<?php echo $times; ?>");
        });
        
        function synchroAddress(customer_code, id){
            $.ajax({
                type : 'post',
                url : '/index.php/crm/Callplatform/synchroAddress',
                data : 'customer_code='+customer_code+'&id='+id,
                dataType : 'json',
                success : function (result) {
                    //alert(JSON.stringify(result));
                    $("#delivery_address_id").val(result.province+' '+result.city+' '+result.area+' '+result.address_details);
                    $("#province_id").val(result.province);
                    $("#city_id").val(result.city);
                    $("#area_id").val(result.area);
                }
            })
        }

        function call_outbound(customer_code){
            var id = $('#id').val();
            // alert(id);
            if (!id) return false;
            $.ajax({
                type : 'post',
                url : '/index.php/crm/Pbx/call_outbound',
                data : {src_exten:exten,customer_code:customer_code,id:id},
                dataType : 'json',
                success : function (result) {
                    if (result.success) {  
                        
                    } else {  
                        
                    }
                }
            })
            
        }
        /* addorder end */
    </script>
</html>
